import axios from 'axios'


let baseURL = import.meta.env.VITE_BASE_ALSO_URL
const apiServer = axios.create({
  baseURL: baseURL,
  timeout: 30000,
  headers: {
    contentType: 'application/json'
  }
})

apiServer.interceptors.request.use(config => {
  return config
}, err => {
  return Promise.reject(err)
})

apiServer.interceptors.response.use(response => {
  const res = response.data
  return Promise.resolve(res)
}, err => {
  console.log("拦截器error",err);
  //网络超时异常处理
  if(err.code === 'ECONNABORTED' || err.message.includes("timeout")){  
    // console.log('请检查网络连接是否正常')
    console.log('请检查网络连接是否正常');
  } else {
    console.log('请检查网络连接是否正常');
    // console.log('请求接口异常')
  }
  return Promise.reject(err)
})

export default apiServer
